package com.pilipili.servicebase.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * MP修改数据库所需的元数据配置
 * @author Unlimited_Blade_Works
 */
//注入组件
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * MP执行添加操作时执行,MetaObject metaObject表的元数据
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("gmtCreate",new Date(),metaObject);
        this.setFieldValByName("gmtModified",new Date(),metaObject);
        this.setFieldValByName("version",1,metaObject);
    }
    /**
     * MP执行修改操作时执行
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified",new Date(),metaObject);
    }
}
